package com.hqyj.controller;


import com.hqyj.pojo.Permission;
import com.hqyj.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author rock
 * @since 2021-10-21
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    IPermissionService permissionService;

    //管理用户列表
    @RequestMapping("/permissionList")
    public HashMap<String,Object> permissionListPage(Permission permission){
        HashMap<String,Object> map = permissionService.queryAll(permission);
        return map;
    }

    @RequestMapping("/updatePermission")
    public HashMap<String, Object> updatePermission(Model model, Permission permission){
        HashMap<String, Object> map = permissionService.update(permission);
        if(map.get("info").equals("保存成功")){
            model.addAttribute("info","保存成功");
        }else {
            model.addAttribute("info", "保存失败");
        }
        return map;
    }

    @RequestMapping("/addPermission")
    public HashMap<String, Object> addPermission(Model model, Permission permission){
        HashMap<String, Object> map = permissionService.addPermission(permission);
        if(map.get("info").equals("保存成功")){
            model.addAttribute("info","保存成功");
        }else {
            model.addAttribute("info", "保存失败");
        }
        return map;
    }

    @RequestMapping("/delPermission")
    public HashMap<String, Object> delPermission(Integer id){
        return permissionService.delPermission(id);
    }
}

